home *** CD-ROM | disk | FTP | other *** search
- /* -----------------------------------------------------------------
- File: help.c
- XFCN to do 7.0 Help stuff
-
- Version: see kVersionStr below
-
- History: 11-06-90 Alias 1.0d1 JRP from volCheck.c
- 11-12-90 1.0d2 JRP put version stuff in vers.h
- 11-13-90 1.0d3 JRP add trap and gestalt checking
- 11-14-90 Help 1.0d1 JRP add findStringResId
- revise cmpStrtoResNum
- revise returnMsgNum
- remove alias-specific functions
- revise vers.h content and usage
- 11-16-90 1.0d2 JRP add ShowIfBalloon
- 11-29-90 1.0d3 JRP add gfun.c stuff
- add getHotRect for ShowBalloon
- 12-04-90 1.0d4 JRP hotRect works only if the user has
- show balloons turned on.
- 01-18-91 1.1d1 JRP major revision for 7.0b3
- set ShowBalloon == ShowIfBalloon
- add commands On, Off, and Disable
- 02-19-91 1.2d1 JRP additional parameters for Mr.Big
- 09-23-91 1.3d1 JRP add ShowBalloonRes command
- 09-Apr-93 1.4 JRP fix bug in Gestalt call that cause "Write to NIL".
-
- Author: John R. Powers, III
- Electronic Media Group
- Instructional Products Department
- Apple Computer, Inc.
- AppleLink: JohnPowers
-
- Copyright: see vers.h and "copyright" below.
-
- Computer: Mac Quadra 950 with System 7.1
-
- Compiler: MPW 3.2.2
-
- Usage:
-
-
- Requires HyperCard version 1.2 or better.
- There are HyperCard callbacks in this XFCN,
- see gfun.c for callback information.
-
- Files:
-
- vers.h header with version information
- help.c This source file
- help.r Rez source
- gfun.c source for using HyperCard globals
- gfun.pro prototypes for gfun.c
- trap.c source for using Gestalt
- trap.pro prototypes for trap.c
- buildHelp sets up and executes the make
- makefileHelp make file
- helpLab HyperCard stack for testing
-
- Full Build:
-
- see makefileHelp and the buildXCMD script
-
- buildXCMD "gfxPak:XCMDs:Mr.Big:Help:", "Help", "helpLab"
-
- Parameter Usage for the ShowBalloon command:
-
- The following table shows the required parameters
- for each type of ShowBalloon (added 1.2d1):
-
- type cmd text tip rect entry inset
-
- basic 1 2 3
-
- interm.A 1 2 3 4
-
- interm.B 1 2 4 5
-
- advanced 1 2 4 5 6
-
- basic puts up balloon variant #0 at the tip location
- you specify.
-
- interm.A puts up balloon variant #0 at the tip location
- you specify and passes a hot rect to HM.
-
- interm.B puts up the best balloon variant for the
- quadrant in which entry is located using
- a fixed inset for the tip. (added 1.2d1)
-
- advanced puts up the best balloon variant for the
- quadrant in which entry is located and uses
- your inset for the tip. (added 1.2d1)
-
-
- ----------------------------------------------------------------- */
-
- #include <HyperXCmd.h>
- #include <Types.h>
- #include <CType.h>
- #include <String.h> /* strcpy.... */
- #include <Strings.h> /* c2pstr.... */
- #include <Memory.h>
- #include <ToolUtils.h>
- #include <Resources.h>
- #include <Packages.h>
- #include <Files.h>
- #include <Errors.h>
-
- #include <Balloons.h>
-
- /*
- Constants
- */
-
- #define kCterm '\0'
- #define kColon ':'
- #define kReturn '\n'
- #define kComma ','
- #define kSpace ','
- #define kCommaStr ","
- #define kReturnStr "\n"
- #define kSpaceStr " "
- #define kNoStringResource "Err 00 Missing STR# for "
-
- #include "vers.h" /* version and copyright info */
-
- enum /* STR indices */
- {
- ksCmdVersion=1, /* first of commands */
- ksCmdHelp,
- ksCmdShowBalloon,
- ksCmdShowBalloonRes, // 09-23-91 1.3d1 added
- ksCmdRemoveBalloon,
- ksCmdShowIfBalloon,
- ksCmdOn,
- ksCmdOff,
- ksCmdDisable,
- ksHelpDesc, /* help description */
- ksGlobalName, /* name of our HyperCard global */
- ksErrCommandWhere, /* first of error messages */
- ksErrCommandHuh,
- ksErrParameters,
- ksErrNoHelpMgr,
- ksErrPointParam,
- ksErrRectParam,
- ksErrShowBalloon,
- ksErrSetBalloons,
- ksErrRemoveBalloon,
- ksErrNoMemory,
- ksErrStoreGlobal,
- ksErrHelpNotOn,
- ksErrNotYet
- };
-
- enum /* parameter indices */
- {
- kParamCmd, /* command */
- kParamText, /* help message text */
- kParamLevel=kParamText, /* level number */
- kParamTip, /* location for balloon tip */
- kParamRect, /* hot rectangle */
- kParamEntry, /* point of entry into object */
- kParamOffset, /* tip offset */
- kParamResName=kParamText, // STR# resource name (alternative)
- kParamResInx // STR# index (alternative)
- };
- /* The ShowBalloon command requires */
- /* a minimum of 3, 4, or 5 parameters */
- #define kMinParamShowA 3
- #define kMinParamShowB 5
- /* default tip offsets */
- #define kOffsetHorz 10
- #define kOffsetVert 10
-
- enum /* tip location variants in HM */
- {
- kTip0=0, /* starts at 10 o'clock and goes CW */
- kTip1,
- kTip2,
- kTip3,
- kTip4,
- kTip5,
- kTip6,
- kTip7
- };
-
- /*
- Macros
- */
-
- #define ABS(x) (((x)<0)?(-(x)):(x))
-
- /*
- Structures
- */
-
- typedef union { /* for our Rect manipulations */
- Rect altRect;
- struct {
- Point topLeft;
- Point botRight;
- } altPoints;
- } rectRecType, *rectPtrType, **rectHanType;
-
- /*
- Prototypes
- */
-
- void addStrItemToList(char *, char *);
- void addNumItemToList(char *, long);
- short cmpStrtoResNum(Str255, short, short);
- void copyPtoCstr(char *, Str255);
- Handle copyStrToHand(char *);
- short equalPstr(Str255, Str255);
- short findStrResId(Str255);
- short getHotRect(XCmdPtr, Str255, short, Rect **, Str255);
- void getItemFromCList(char *, short, char *);
- void getItemFromPList(Str255, short, Str255);
- void handleToCstr(char *, Handle);
- void handleToNum(long *, Handle);
- void handleToPstr(Str255, Handle);
- short pointFromPstr(Point *, Str255);
- short rectFromPstr(Rect *, Str255);
- void returnMsgNum(XCmdPtr, short, short, long);
- void selectBalloon(Point *, short *, Point *, Rect *, Point *);
-
- #include "trap.pro"
- #include "gfun.pro"
-
- /*
- DEBUG_MSG_HAN(msg, han) displays the message, msg,
- and dumps the memory referenced by the handle, han.
- */
-
- #define DEBUG_MSG_HAN(msg, han) \
- { \
- char debugCstr[50],hexCstr[10]; \
- strcpy(debugCstr,msg); \
- strcat(debugCstr," ;dm "); \
- convertHanToHexStr(hexCstr, (Handle) han); \
- strcat(debugCstr,hexCstr); \
- strcat(debugCstr, "^ "); \
- DebugStr((Str255)c2pstr(debugCstr)); \
- }
- /*
- Set kccDbAltRect true to debug (display) the
- alternativeRect.
- */
-
- #define kccDbAltRect false
-
- /*
- Main program and entry point for XFCN.
- */
-
- pascal void entryPoint(paramPtr)
- /*
- */
-
- XCmdPtr paramPtr; /* the HyperCard connection */
- {
- char resultStr[1024],
- copyright[]=kCopyrightStr;
- Str255 command,
- pointPstr,
- globalNamePstr;
- OSErr err;
- short strResId,
- turnOn,
- tipProvided;
- long level;
- short paramInxOffset;
- char resNameStr[64];
- Str255 resInxStr;
- long resIndex;
- /* Help manager structures */
- HMMessageRecord HMR;
- Point tip,
- entryLoc,
- tipInset;
- Ptr pTipProc;
- short theProc,
- variant,
- method;
- Rect *pQdRect; /* pointer to saved Rect */
-
- *resultStr = kCterm;
- if(paramPtr->paramCount<0)
- return; /* an event, ignore */
- /* Get the string resource ID */
- /* for our named STR# */
- strResId = findStrResId(kProgNameStr);
- if(!strResId)
- { /* Oh-oh, our STR# is missing */
- strcpy(resultStr, kNoStringResource);
- strcat(resultStr, kProgNameStr);
- paramPtr->returnValue = copyStrToHand(resultStr);
- return;
- }
- /* get our global, if any */
- GetIndString(globalNamePstr, strResId, ksGlobalName);
- /* check for command */
- if(paramPtr->paramCount==0)
- {
- returnMsgNum(paramPtr, ksErrCommandWhere, strResId, 0);
- return;
- }
- handleToPstr(command, paramPtr->params[kParamCmd]);
- /* version command? */
- if(cmpStrtoResNum(command, ksCmdVersion, strResId))
- {
- strcpy(resultStr, kProgNameStr);
- strcat(resultStr, kSpaceStr);
- strcat(resultStr, kVersionStr);
- strcat(resultStr, kSpaceStr);
- strcat(resultStr, kAuthorStr);
- paramPtr->returnValue = copyStrToHand(resultStr);
- return;
- }
- /* help command? */
- else if(cmpStrtoResNum(command, ksCmdHelp, strResId))
- {
- returnMsgNum(paramPtr, ksHelpDesc, strResId, 0);
- return;
- }
- else if(!helpMgrPresent()) /* check for Help Manager */
- {
- returnMsgNum(paramPtr, ksErrNoHelpMgr, strResId, 0);
- return;
- }
- /* The following commands require */
- /* the Help Manager */
-
- /* The show commands require */
- /* that Balloon Help be enabled */
- /* If it isn't, return right now. */
- if(!HMGetBalloons()
- && (cmpStrtoResNum(command, ksCmdShowBalloon, strResId)
- ||
- cmpStrtoResNum(command, ksCmdShowIfBalloon, strResId)))
- {
- paramPtr->returnValue = nil;
- return;
- }
- /* Check for On or Off. */
- /* If either, then the state of */
- /* turnOn is the desired state. */
- if((turnOn = cmpStrtoResNum(command, ksCmdOn, strResId))
- || cmpStrtoResNum(command, ksCmdOff, strResId))
- {
- if(err = HMSetBalloons(turnOn))
- {
- returnMsgNum(paramPtr, ksErrSetBalloons, strResId, err);
- return;
- }
- else
- {
- paramPtr->returnValue = nil;
- return;
- }
- }
- /* Disable, level? */
- if(cmpStrtoResNum(command, ksCmdDisable, strResId))
- {
- if(paramPtr->paramCount<2)
- level = 0;
- else
- handleToNum(&level, paramPtr->params[kParamText]);
- /* At this point, we need to make */
- /* some neat call to HM to set the */
- /* disable level (Right after */
- /* Randy implements it.) */
- returnMsgNum(paramPtr, ksErrNotYet, strResId, 0);
- return;
- }
-
- /* ShowBalloon or */
- /* ShowBalloonSTR or */
- /* ShowIfBalloon command? */
- if(cmpStrtoResNum(command, ksCmdShowBalloon, strResId)
- || cmpStrtoResNum(command, ksCmdShowIfBalloon, strResId)
- || cmpStrtoResNum(command, ksCmdShowBalloonRes, strResId))
- {
- if(cmpStrtoResNum(command, ksCmdShowBalloonRes, strResId))
- { // ShowBalloonRes (STR resource name and index)
- paramInxOffset = 1; // use alternative parameter indexes
- if(paramPtr->paramCount<(kMinParamShowA+paramInxOffset))
- { /* not enough parameters */
- returnMsgNum(paramPtr, ksErrParameters, strResId, 0);
- return;
- }
- HMR.hmmHelpType = khmmStringRes;
- // get STR# name, convert to ID
- handleToCstr(resNameStr, paramPtr->params[kParamResName]);
- HMR.u.hmmStringRes.hmmResID = findStrResId(resNameStr);
- // get STR# index
- handleToPstr(resInxStr, paramPtr->params[kParamResInx]);
- StringToNum(resInxStr, &resIndex);
- HMR.u.hmmStringRes.hmmIndex = (short) resIndex;
- }
- else
- { // ShowBalloon or ShowIfBalloon
- paramInxOffset = 0; // use default parameter indexes
- if(paramPtr->paramCount<kMinParamShowA)
- { /* not enough parameters */
- returnMsgNum(paramPtr, ksErrParameters, strResId, 0);
- return;
- }
- /* get text of help */
- HMR.hmmHelpType = khmmString;
- handleToPstr((Str255) HMR.u.hmmString, paramPtr->params[kParamText]);
- }
- /* then the tip */
- variant = kTip0; /* default balloon tip variant */
- handleToPstr(pointPstr, paramPtr->params[kParamTip+paramInxOffset]);
- if(tipProvided=(pointPstr[0]>0))
- {
- if(!pointFromPstr(&tip, pointPstr))
- {
- returnMsgNum(paramPtr, ksErrPointParam, strResId, 0);
- return;
- }
- LocalToGlobal(&tip);
- }
- if(paramPtr->paramCount<=(kMinParamShowA+paramInxOffset))
- pQdRect = nil; /* no hot rect parameter */
- else /* optional hot rect */
- {
- Str255 rectPstr;
-
- handleToPstr(rectPstr, paramPtr->params[kParamRect+paramInxOffset]);
- if(!getHotRect(paramPtr, globalNamePstr, strResId, &pQdRect, rectPstr))
- { /* error, message already setup */
- return;
- }
- }
- if(!tipProvided)
- { /* empty point, need other params */
- if(paramPtr->paramCount<kMinParamShowB)
- { /* not enough parameters */
- returnMsgNum(paramPtr, ksErrParameters, strResId, 0);
- return;
- }
- /* entry point into object */
- handleToPstr(pointPstr, paramPtr->params[kParamEntry+paramInxOffset]);
- if(!pointFromPstr(&entryLoc, pointPstr))
- {
- returnMsgNum(paramPtr, ksErrPointParam, strResId, 0);
- return;
- }
- LocalToGlobal(&entryLoc);
- /* offset for balloon tip */
- handleToPstr(pointPstr, paramPtr->params[kParamOffset+paramInxOffset]);
- if(pointPstr[0]==0)
- { /* empty, use defaults */
- tipInset.h = kOffsetHorz;
- tipInset.v = kOffsetVert;
- }
- else if(!pointFromPstr(&tipInset, pointPstr))
- {
- returnMsgNum(paramPtr, ksErrPointParam, strResId, 0);
- return;
- }
- selectBalloon(&tip, &variant, &entryLoc, pQdRect, &tipInset);
- }
- pTipProc = nil;
- theProc = 0;
- method = kHMRegularWindow;
- err = HMShowBalloon(&HMR, tip, pQdRect, pTipProc,
- theProc, variant, method);
- if(err)
- {
- returnMsgNum(paramPtr, ksErrShowBalloon, strResId, err);
- return;
- }
- paramPtr->returnValue = nil;
- return;
- }
- /* RemoveBalloon command? */
- if(cmpStrtoResNum(command, ksCmdRemoveBalloon, strResId))
- {
- if(HMIsBalloon())
- if(err = HMRemoveBalloon())
- {
- returnMsgNum(paramPtr, ksErrRemoveBalloon, strResId, err);
- return;
- }
- paramPtr->returnValue = nil;
- return;
- }
- else
- {
- returnMsgNum(paramPtr, ksErrCommandHuh, strResId, 0);
- return;
- }
- } /* -------------------------------------------- entryPoint */
-
- /*
- Functions
- */
-
- void addNumItemToList(pList, num)
- /*
- Add num to pList.
-
- Preceed each item with a comma.
- The comma will not be added as
- the first item in a string or
- the first item in a line.
- */
- char *pList;
- long num;
- {
- Str255 tempPstr;
-
- NumToString(num, tempPstr);
- addStrItemToList(pList, p2cstr(tempPstr));
- } /* -------------------------------------------- addNumItemToList */
-
- void addStrItemToList(pList, pAdd)
- /*
- Add pAdd to pList.
-
- Preceed each item with a comma.
- The comma will not be added as
- the first item in a string or
- the first item in a line.
- */
- char *pList,
- *pAdd;
- {
- short len;
-
- if(len=strlen(pList))
- if(pList[len-1]!=kReturn)
- strcat(pList, kCommaStr);
- strcat(pList, pAdd);
- } /* -------------------------------------------- addStrItemToList */
-
- short cmpStrtoResNum(theString, theStrNum, strResId)
- /*
-
- 08/17/90 1.0a2 MJP new (GFXMenu)
- 11-14-90 1.0d1 JRP add strResId as parameter
- */
- Str255 theString;
- short theStrNum,
- strResId;
-
- {
- Str255 ResString;
-
- GetIndString(ResString, strResId, theStrNum);
- return (equalPstr(ResString, theString));
- } /* -------------------------------------------- cmpStrtoResNum */
-
- void copyPtoCstr(Cstr, Pstr)
- /*
- Copy the Pstr to the Cstr.
- Don't do it in-place like p2cstr.
- */
- Str255 Pstr;
- char *Cstr;
- {
- short i;
-
- for(i=1; i<=Pstr[0]; i++)
- *Cstr++ = Pstr[i];
- *Cstr = 0;
- } /* --------------------------------------- copyPtoCstr */
-
- Handle copyStrToHand(str)
- /*
- Create a handle and copy the string to it.
- Return the handle.
- */
- char *str;
- {
- Handle newHndl;
-
- newHndl = (Handle) NewHandle((long) strlen(str) + 1);
- HLock(newHndl);
- strcpy(*newHndl, str);
- HUnlock(newHndl);
- return(newHndl);
- } /* -------------------------------------------- copyStrToHand */
-
- short equalPstr(s1, s2)
- /*
- Compare s1 and s2.
- If their contents are equal and they are of equal length, return TRUE.
- Comparison is not case-sensitive.
- */
- Str255 s1,
- s2;
- {
- short i,
- c1,
- c2;
-
- if(s1[0]!=s2[0])
- return false;
- for(i=1; i<=s1[0]; i++)
- {
- c1 = tolower(s1[i]);
- c2 = tolower(s2[i]);
- if(c1!=c2)
- return false;
- }
- return true;
- } /* -------------------------------------------- equalPstr */
-
- short findStrResId(resName)
- /*
- Given the name of a STR# resource, return
- its ID number. This lets us use names instead
- of ID's for tracking STR# resources.
- */
- char *resName;
- {
- Handle hRes;
- short theID;
- ResType theType;
- Str255 theName;
-
- strcpy(theName, resName);
- hRes = GetNamedResource('STR#', c2pstr(theName));
- if(!hRes || ResError())
- return 0;
- GetResInfo(hRes, &theID, &theType, theName);
- if(ResError()==resNotFound)
- return 0;
- else
- return theID;
- } /* -------------------------------------------- findStrResId */
-
- short getHotRect(paramPtr, globalNamePstr, strResId, ppQdRect, rectPstr)
- /*
- Return the pQdRect after extracting and converting
- the HyperCard local rectangle on the parameter list.
-
- 11-30-90 1.0d3 JRP new
- 12-03-90 1.0d4 JRP must return ppQdRect by reference, not value
-
- Return true if successful, false if error
- */
- XCmdPtr paramPtr;
- Str255 globalNamePstr;
- short strResId;
- Rect **ppQdRect; /* pointer to the Rect Ptr */
- Str255 rectPstr; /* HC rect in string form */
- {
- Rect hcRect; /* HC rect in HC rect form */
- Handle hHelpRect; /* handle to saved Rect */
- rectPtrType pHelpRect; /* local copy of rect pointer */
-
- *ppQdRect = nil;
- if(!fetchHanFromGlobal(paramPtr, globalNamePstr, &hHelpRect))
- { /* create storage for hot rect */
- hHelpRect = NewHandleClear(sizeof(rectRecType));
- if(hHelpRect==nil || MemError())
- { /* couldn't get memory for rect */
- returnMsgNum(paramPtr, ksErrNoMemory, strResId, 0);
- return false;
- }
- MoveHHi(hHelpRect);
- if(storeHanInGlobal(paramPtr, globalNamePstr, hHelpRect))
- { /* error storing global */
- returnMsgNum(paramPtr, ksErrStoreGlobal, strResId, 0);
- return false;
- }
- }
- /* get optional HyperCard rect */
- if(!rectFromPstr(&hcRect, rectPstr))
- {
- returnMsgNum(paramPtr, ksErrRectParam, strResId, 0);
- return false;
- }
- /* our saved rect storage */
- HLock(hHelpRect);
- pHelpRect = (rectPtrType) *hHelpRect;
- /* HyperCard to QuickDraw Rect */
- /* copy to saved rect storage */
- pHelpRect->altRect.top = hcRect.left;
- pHelpRect->altRect.left = hcRect.top;
- pHelpRect->altRect.bottom = hcRect.right;
- pHelpRect->altRect.right = hcRect.bottom;
- #if kccDbAltRect
- DEBUG_MSG_HAN("After, QD Rect, Local", hHelpRect);
- #endif
- /* Local to Global Coordinates */
- LocalToGlobal(&(pHelpRect->altPoints.topLeft));
- LocalToGlobal(&(pHelpRect->altPoints.botRight));
- #if kccDbAltRect
- DEBUG_MSG_HAN("After, QD Rect, Global", hHelpRect);
- #endif
- *ppQdRect = (Rect *) pHelpRect; /* return ptr to rect */
- return true; /* success */
- } /* -------------------------------------------- getHotRect */
-
- void getItemFromCList(itemListCstr, itemNum, itemCstr)
- /*
- Return the itemNum-th item in the itemListCstr.
- Stops at end of string or Return character (end of HyperCard line).
- Returns terminator if item not present.
- Does not return any punctuation (comma or return).
- */
- char *itemListCstr;
- short itemNum;
- char *itemCstr;
- {
- short itemCnt=1;
-
- /* Count commas to get itemNum-th item */
- while(itemCnt<itemNum && *itemListCstr!=0 && *itemListCstr!=kReturn)
- if(*itemListCstr++==kComma)
- itemCnt++;
- /* Copy itemNum-th item */
- /* skip leading spaces */
- if(itemCnt==itemNum)
- {
- while(*itemListCstr!=0 && *itemListCstr!=kReturn && *itemListCstr==kSpace)
- itemListCstr++;
- while(*itemListCstr!=0 && *itemListCstr!=kReturn && *itemListCstr!=kComma)
- *itemCstr++ = *itemListCstr++;
- }
- *itemCstr = kCterm;
-
- } /* -------------------------------------------- getItemFromCList */
-
- void getItemFromPList(itemListPstr, itemNum, itemPstr)
- /*
- Return the itemNum-th item in the itemListPstr
- */
- Str255 itemListPstr;
- short itemNum;
- Str255 itemPstr;
- {
- short i=1,
- j=0,
- itemCnt=1;
- /* Count commas to get itemNum-th item */
- while(itemCnt<itemNum && i<itemListPstr[0])
- if(itemListPstr[i++]==kComma)
- itemCnt++;
- /* Copy itemNum-th item */
- if(itemCnt==itemNum)
- while(i<=itemListPstr[0] && itemListPstr[i]!=kComma)
- itemPstr[++j] = itemListPstr[i++];
- itemPstr[0] = j;
- } /* -------------------------------------------- getItemFromPList */
-
- void handleToCstr(str, hndl)
- /*
- Return a copy of the string contained in the handle.
- If the handle is NIL, return an empty string.
- */
- char *str;
- Handle hndl;
- {
- if(hndl==nil)
- *str = kCterm;
- else
- {
- HLock(hndl);
- strcpy(str, *hndl);
- HUnlock(hndl);
- }
- } /* -------------------------------------------- handleToCstr */
-
- void handleToNum(num, hndl)
- /*
- Return the number contained the string contained in the handle.
- If the handle is NIL, return zero.
-
- Don't want to convert the handle string from C-string to
- Pascal string in-place. Copy to a local string first.
- */
- long *num;
- Handle hndl;
- {
- char str[32];
-
- if(hndl==nil)
- *num = 0;
- else
- {
- HLock(hndl);
- strcpy((char *)str, *hndl);
- HUnlock(hndl);
- StringToNum(c2pstr(str), num);
- }
- } /* -------------------------------------------- handleToNum */
-
- void handleToPstr(str, hndl)
- /*
- Return a copy of the string contained in the handle.
- If the handle is NIL, return an empty string.
- */
- Str255 str;
- Handle hndl;
- {
- if(hndl==nil)
- str[0] = 0;
- else
- {
- HLock(hndl);
- strcpy((char *)str, *hndl);
- HUnlock(hndl);
- c2pstr(str);
- }
- } /* -------------------------------------------- handleToPstr */
-
- short pointFromPstr(tip, pointPstr)
- /*
- Pass a Pascal string containing two coordinates
- in the form "h,v". The point will be returned
- in tip.
-
- true is returned if successful.
- false if an error.
- */
- Point *tip;
- Str255 pointPstr;
- {
- Str255 pointHPstr,
- pointVPstr;
- long tempLong;
-
- getItemFromPList(pointPstr, 1, pointHPstr);
- getItemFromPList(pointPstr, 2, pointVPstr);
- if(pointHPstr[0]==0 || pointVPstr[0]==0)
- return false;
- StringToNum(pointHPstr, &tempLong);
- tip->h = tempLong;
- StringToNum(pointVPstr, &tempLong);
- tip->v = tempLong;
- return true;
- } /* -------------------------------------------- pointFromPstr */
-
- short rectFromPstr(theRect, rectPstr)
- /*
- Pass a Pascal string containing a rect
- in the form "t,l,b,r". The rect will be returned
- in theRect.
-
- true is returned if successful.
- false if an error.
- */
- Rect *theRect;
- Str255 rectPstr;
- {
- Str255 rectItemPstr;
- long tempLong;
- short i;
-
- for(i=1; i<=4; i++)
- {
- getItemFromPList(rectPstr, i, rectItemPstr);
- if(rectItemPstr[0]==0)
- return false;
- StringToNum(rectItemPstr, &tempLong);
- switch(i)
- {
- case 1:
- theRect->top = tempLong;
- break;
- case 2:
- theRect->left = tempLong;
- break;
- case 3:
- theRect->bottom = tempLong;
- break;
- case 4:
- theRect->right = tempLong;
- break;
- }
- }
- return true;
- } /* -------------------------------------------- rectFromPstr */
-
- void returnMsgNum(paramPtr, strNum, strResId, num)
- /*
- Given the STR# number and a number,
- place the string and the number
- in the return to HyperCard.
- The num is optional, if 0 then it is not placed.
- No space or punctuation is added between the string
- and the num.
-
- 11-14-90 1.0d1 JRP add strResId as a parameter
- 11-30-90 1.0d3 JRP append num directly rather than addNumItemToList
- */
- XCmdPtr paramPtr; /* the HyperCard connection */
- short strNum,
- strResId;
- long num;
- {
- Str255 resPstr,
- tempPstr;
- char resultStr[256];
-
- GetIndString(resPstr, strResId, strNum);
- strcpy(resultStr, p2cstr(resPstr));
- if(num!=0)
- {
- NumToString(num, tempPstr);
- strcat(resultStr, p2cstr(tempPstr));
- }
- paramPtr->returnValue = copyStrToHand(resultStr);
- } /* -------------------------------------------- returnMsgNum */
-
- void selectBalloon(pTipLoc, pVariant, pEntryLoc, pObjRect, pTipInset)
- /*
- Calculate the pTipLoc and balloon tip pVariant
- given:
- pEntryLoc cursor location in object
- pObjRect the object rectangle
- pTipInset the inset desired for the tip
-
- by computing which quadrant the pEntryLoc is in
- and, from that and the pObjRect, generating a
- balloon tip location, pTipLoc, and balloon tip
- pVariant that will not obscure the object.
-
- If pTipInset.h!=pTipInset.v, this function will select
- a balloon pVariant that will minimize obscuring
- the pObjRect.
-
-
- All coordinates are global.
- You're right, pEntryLoc and pTipInset did not have
- to be passed as pointers. But here they are anyway.
- */
- Point *pTipLoc;
- short *pVariant;
- Point *pEntryLoc;
- Rect *pObjRect;
- Point *pTipInset;
- {
- Point middle;
- /* divide object into quadrants */
- middle.v = pObjRect->top
- + ((ABS(pObjRect->bottom) - ABS(pObjRect->top)) / 2);
- middle.h = pObjRect->left
- + ((ABS(pObjRect->right) - ABS(pObjRect->left)) / 2);
- /* locate pEntryLoc in quadrant */
- if(pEntryLoc->v>middle.v)
- { /* below the mason-dixon line */
- pTipLoc->v = pObjRect->bottom - pTipInset->v;
- if(pEntryLoc->h>middle.h)
- { /* southeast quadrant */
- pTipLoc->h = pObjRect->right - pTipInset->h;
- if(pTipInset->h>pTipInset->v)
- *pVariant = kTip0;
- else
- *pVariant = kTip1;
- }
- else
- { /* southwest quadrant */
- pTipLoc->h = pObjRect->left + pTipInset->h;
- if(pTipInset->h>pTipInset->v)
- *pVariant = kTip3;
- else
- *pVariant = kTip2;
- }
- }
- else
- { /* above the mason-dixon line */
- pTipLoc->v = pObjRect->top + pTipInset->v;
- if(pEntryLoc->h>middle.h)
- { /* northeast quadrant */
- pTipLoc->h = pObjRect->right - pTipInset->h;
- if(pTipInset->h>pTipInset->v)
- *pVariant = kTip7;
- else
- *pVariant = kTip6;
- }
- else
- { /* northwest quadrant */
- pTipLoc->h = pObjRect->left + pTipInset->h;
- if(pTipInset->h>pTipInset->v)
- *pVariant = kTip4;
- else
- *pVariant = kTip5;
- }
- }
- } /* -------------------------------------------- selectBalloon */
-